Identifiers in C


Identifiers are the user-defined names (with a sequence of letters and digits) given to the variables, arrays, functions, structures, unions etc.

For example: In terms of computer, it uses the range of addresses to identify the data. But as a programmer, we can't get those addresses before program execution. so rather than using addresses, we use identifiers. 

Rules of identifiers :

In order to remove the ambiguity during the compilation process, C creators imposed a set of rules on identifiers. They are :

  • The first character must start with a letter (A to Z) or (a to z) or with an underscore (_).
  • An identifier should contain only letters (A to Z) or (a-z) or digits (0 to 9) or an underscore (_).
  • Identifers are case-sensitive i.e  "EXAMPLE", "example", "Example", "eXample" are four different identifiers.
  • Identifiers should not contain any 'special characters' & 'white space characters' except underscore.

Special characters:

+ * \ <
> ( { [
, ' ; ?
& ~ # -
% / = ^
) } ] .
" ; ! |

 

Whitespace characters:

Space     newline (\n) horizontal tab (\t)
Vertical tab (\v) formfeed (\f)  

 

  • Keywords are not allowed to use as identifiers because keywords are the reserved words.

Valid identifiers:

  • _dataoverride
  • c_tutorials1
  • jamesbond007
  • Final__Example

Invalid identifiers:

  • 123example
  • @example2
  • data override
  • float (It is invalid because the float is a keyword)

Note:

Refer "page 192  section A2.3  Identifiers" in "The C programming language by Dennis M Ritchie & Brian W. Kernighan". This book was written by creators of C.

If you didn't purchase this book yet, I strongly recommend you to get a copy of this book @ click here to get this book. 

Reference videos:

 





© 2020 Pragimtech. All Rights Reserved.